﻿Type.registerNamespace("jjon");


jjon.Membership = function() {
    this._waitId = "";
    this._waitmsg = null;
}

jjon.Membership.prototype =
{
    get_WaitLabelId: function() {
        return this._waitId;
    },
    set_WaitLabelId: function(value) {
        this._waitId = value;
    },
    BeginLogin: function(uid, pwd, rememberme) {
        this._waitmsg = new jjon.ProgressMessage(this._waitId);
        this._waitmsg.ShowMessage("Autenticando...");
        Sys.Services.AuthenticationService.login(uid, pwd, rememberme, null, null, Function.createDelegate(this, this.EndLogin), Function.createDelegate(this, this.OnError), null);
    },
    EndLogin: function(result, context, methodname) {
        if (result) {
            this.BeginRoleLoad();
        }
        else {
            this._waitmsg.HideMessage();
            alert("Senha ou Login Inválido!");
        }
    },
    BeginLogout: function() {
    },
    EndLogout: function(result, context, methodname) {
    },
    BeginRoleLoad: function() {
        Sys.Services.RoleService.load(Function.createDelegate(this, this.EndRoleLoad), Function.createDelegate(this, this.OnError));
    },
    EndRoleLoad: function(result) {

    if (this.IsUserInRole("klant")) 
        window.location.href = "klantagenda.aspx";
        else window.location.href = "Author/cpanel.aspx";
    },
    IsUserInRole: function(roleName) {
        return Sys.Services.RoleService.isUserInRole(roleName);
    },
    OnError: function(result, context, methodname) {
        waitmsg.HideMessage();
        alert(err.get_message());
    }
}

jjon.Membership.registerClass("jjon.Membership");

